<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

</head>
<style>
    * {
        margin: 0;
        padding: 0;
    }

    body,
    html,
    #app {
        height: 100%;
    }

    .left,
    .right {
        width: 48%;
        height: 100%;
        float: left;
        box-sizing: border-box;


    }

    .right {
        padding: 10px 30px;
        font-size: 18px;
    }

    .left {
        border: none;
        outline: none;
        resize: none;
        background-color: aquamarine;
        border-right: 1px solid #ccc;
        font-size: 16px;
        padding: 20px;

    }
</style>

<body>
    <div id="app">
        <textarea class="left" :value="content" @input="debounce($event)"></textarea>
        <div class="right" v-html="mark">{{content}}</div>
    </div>

</body>

</html>
<script src="https://cdn.bootcdn.net/ajax/libs/marked/1.2.7/marked.min.js"></script>
<script src='https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js'></script>
<script>
    let vm = new Vue({
        el: "#app",
        data: {
            content: "# 一级标题",
            timer: null
        },
        methods: {
            //防抖
            debounce(e) {
                if (this.timer) {
                    clearTimeout(this.timer)
                }
                this.timer = setTimeout(() => {
                    console.log(e)
                    this.content = e.target.value
                }, 300)
            }
        },
        computed: {
            mark() {
                return marked(this.content)
            }
        }
    })
</script>